package com.example.libo.huihui;

import android.app.Activity;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.libo.huihui.adapter.FragmentAdapter;
import com.example.libo.huihui.fragment.ShaiwuFragment;

public class MainActivity extends AppCompatActivity{
    private TabLayout tab;
    private ViewPager viewPager;
    private FragmentAdapter adapter;
    private Fragment[] findFgtArr;
    private String[] titles = {"晒物","资讯","海淘","国内","清单"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init();
    }

    private void init() {
        tab = (TabLayout) findViewById(R.id.tab);
        viewPager = (ViewPager) findViewById(R.id.find_pager);
        viewPager.setOffscreenPageLimit(4);
        findFgtArr = new Fragment[]{new ShaiwuFragment(), new ShaiwuFragment(), new ShaiwuFragment(), new ShaiwuFragment(), new ShaiwuFragment()};

        setTitle();
    }

    private void setTitle(){
        adapter = new FragmentAdapter(getSupportFragmentManager(), titles, findFgtArr);
        viewPager.setAdapter(adapter);
        tab.setupWithViewPager(viewPager);
        tab.getTabAt(0).select();
    }
}
